// random/pages/order/order.js
var common = require("../../../common/common.js").common;

const app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        page: 1,
        rows: 10,
        chooseClass: 0
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getList();
        this.getMyInfo();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        this.getList();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function(e) {
        if (e.target.dataset.item) {
            common.request({
                endpoint: "Random/manage/share-record",
                method: "post",
                data: {
                    activity_id: e.target.dataset.item.activity_id
                },
                success: res => {}
            });
            return {
                title: "你有一个盲盒待领取！",
                imageUrl: e.target.dataset.item.pro_icon,
                path: `/random/pages/center/center?activity_id=${e.target.dataset.item.activity_id}&main_member_id=${this.data.info.m_id}`
            };
        }
    },
    getList: function() {
        let _this = this;
        let {page: page, rows: rows, chooseClass: chooseClass} = _this.data;
        common.request({
            endpoint: "/Random/manage/order-list",
            method: "post",
            data: {
                page: page,
                rows: rows,
                status: chooseClass
            },
            success: res => {
                var list = res.extra;
                list = page == 1 ? list : this.data.list.concat(list);
                _this.setData({
                    list: list,
                    page: page + 1
                });
            }
        });
    },
    chooseClass: function(e) {
        var id = e.currentTarget.dataset.id;
        this.setData({
            chooseClass: id,
            list: [],
            page: 1
        });
        this.getList();
    },
    getMyInfo: function() {
        var that = this;
        var openid = wx.getStorageSync("user").openid;
        common.request({
            endpoint: "My/myinfo/myinfo",
            method: "post",
            data: {
                openid: openid
            },
            success: res => {
                console.log(res);
                that.setData({
                    info: res.extra
                });
            }
        });
    }
});